package com.designpattern.behavior.interpreter;

/**
 * @author Administration
 * @date 2021/10/28 - 17:44 - 星期四
 * @project 行为型模式中的  解释器模式  非终结符表达式角色
 * @package com.designpattern.behavior.interpreter
 * @by 晨
 */
public class Plus extends AbstractExpression{

    private AbstractExpression left;
    private AbstractExpression right;

    public Plus(AbstractExpression left, AbstractExpression right) {
        this.left = left;
        this.right = right;
    }

    @Override
    public int interpret(Context context) {
        return left.interpret(context) + right.interpret(context);
    }

    @Override
    public String toString() {
        return "(" + left.toString() + " + " + right.toString() + ")";
    }
}
